eststo clear

if("`c(os)'"=="Windows"){
	local tableSaveDir = "Tables\DiD\"
	local plotSaveDir = "Plots\"
	local pythonSaveDir = "PythonScripts\"
}
else{
	local tableSaveDir = "Tables/DiD/"
	local plotSaveDir = "Plots/"
	local pythonSaveDir = "PythonScripts/"
}

//Establish Control Variable Sets
local spec1Controls = "c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage"
local spec2Controls = "`spec1Controls'"
local spec3Controls = "`spec2Controls' i.vmtDummyExtSpec3"
local spec4Controls = "`spec2Controls' i.vmtDummyExtSpec4"


//Establish Cluster Variable
local clusterVar = "stateGroup year"

//Absorb Vars are always time and state fixed effects
local absorbVars = "ib51.stateGroup ib1995.year"

//Establish ci level
local ciLevel = 95

//Estimate Models
//Estimate Spec. 1 Travel RF-DiD Model
regFWL logvmt, nosafetyind, `spec1Controls', `absorbVars', `clusterVar', _
eststo spec1
local df = e(N_clust)-1

//Estimate Spec. 2 Travel RF-DiD Model 
regFWL logvmt, nosafetyind, `spec2Controls', `absorbVars', `clusterVar', _
eststo spec2
local df = e(N_clust)-1

//Estimate Spec. 3 Travel RF-DiD Model
regFWL logvmt, nosafetyind, `spec3Controls', `absorbVars', `clusterVar', _
eststo spec3
local df = e(N_clust)-1

//Estimate Spec. 4 Travel RF-DiD Model
regFWL logvmt, nosafetyind, `spec4Controls', `absorbVars', `clusterVar', _
eststo spec4
local df = e(N_clust)-1


//Export Model Results to TeX Files
//Establish Format
local fmtDiD = `"cells(b(fmt(3) star) se(par fmt(3))) keep(nosafetyind_res) nocon label compress longtable mtitles("\makecell{No \\ DSCs}" "\makecell{Documented \\ DSCs}" "\makecell{Suspected \\ DSCs}" "\makecell{Potential \\ DSCs}") starlevels(* 0.1 ** 0.05 *** 0.01) addnotes("* p \textless 0.1, ** p \textless 0.05, *** p \textless 0.01" "Note: All models include state and year fixed effects as well as state-level time trends." "All models cluster standard errors  by state.")"'


//Export Table
esttab spec1 spec2 spec3 spec4 using "`tableSaveDir'VMTRFDiD.tex", `fmtDiD' depvars title("Reduced Form Diff-in-Diff Results - VMT \label{tab:RFDiD}") stats(N r2, labels( "Observation" "R\textsuperscript{2}")fmt(%8.0f %8.3f)) replace


